package xju_5_6.config;

import org.springframework.context.annotation.*;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.TransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;


@Configuration
@ComponentScan(basePackages = "xju_5_6.service")
@EnableTransactionManagement
@EnableAspectJAutoProxy(proxyTargetClass = true)
// 加载 数据源和mybatis的配置类
@Import({DataSourceConfig.class,MybatisConfig.class})
public class SpringConfig {

    // 事务管理器
    @Bean
    public TransactionManager transactionManager(DataSource dataSource) {
        DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager();
        dataSourceTransactionManager.setDataSource(dataSource);
        return  dataSourceTransactionManager;
    }
}
